<cfcomponent>

<!---

The point of this is to act like rereplace, but first we find
the matches, then we see if the match is inside html.
--->
<!---
<cffunction name="reReplaceNoHTML" output="false" returnType="string">
	<cfargument name="regex" type="string" required="true">
	<cfargument name="text" type="string" required="true">
	<cfargument name="replacetext" type="string" required="true">

	<cfset var results = reFindAll(arguments.regex, arguments.text)>
	<cfset var i = "">
	<cfset var result = arguments.text>
	<cfset var good = "">
		
	<cfloop index="i" from="#arrayLen(results.pos)#" to="1" step="-1">
		<cfset good = bad>
		<!--- look to the left. if you see < closer to me before >, its bad --->
		<cfset slice = reverse(mid(result, 1, results.pos[i]))>
		<cfif find("<", slice)>
			<cfif find(">", slice) lt find("<", slice)>
				<cfset good = true>
			<cfelse>
				<cfset good = false>
			</cfif>
		<cfelse>
			<cfset good = true>
		</cfif>
		
		<!--- only chnage if good --->
		<cfif good>
		
			<cfset newString
			<cfif results.pos[i] gt 1>
				
						<cfset arguments.string = left(arguments.string, matches.pos[i] - 1) & newString & 
							mid(arguments.string, matches.pos[i]+matches.len[i], len(arguments.string))>
					<cfelse>
						<cfset arguments.string = newString & 
							mid(arguments.string, matches.pos[i]+matches.len[i], len(arguments.string))>
					</cfif>

		</cfif>
	</cfloop>
	
</cffunction>
--->
<!---
	<b> foo
	reversed:  >b<
--->
<!---
 Returns all the matches of a regular expression within a string.
 
 @param regex 	 Regular expression. (Required)
 @param text 	 String to search. (Required)
 @return Returns a structure. 
 @author Ben Forta (ben@forta.com) 
 @version 1, July 15, 2005 
--->
<cffunction name="reFindAll" output="false" returnType="struct">
   <cfargument name="regex" type="string" required="true">
   <cfargument name="text" type="string" required="true">

   <!--- Define local variables --->	
   <cfset var results=structNew()>
   <cfset var pos=1>
   <cfset var subex="">
   <cfset var done=false>
	
   <!--- Initialize results structure --->
   <cfset results.len=arraynew(1)>
   <cfset results.pos=arraynew(1)>

   <!--- Loop through text --->
   <cfloop condition="not done">

      <!--- Perform search --->
      <cfset subex=reFind(arguments.regex, arguments.text, pos, true)>
      <!--- Anything matched? --->
      <cfif subex.len[1] is 0>
         <!--- Nothing found, outta here --->
         <cfset done=true>
      <cfelse>
         <!--- Got one, add to arrays --->
         <cfset arrayappend(results.len, subex.len[1])>
         <cfset arrayappend(results.pos, subex.pos[1])>
         <!--- Reposition start point --->
         <cfset pos=subex.pos[1]+subex.len[1]>
      </cfif>
   </cfloop>

   <!--- If no matches, add 0 to both arrays --->
   <cfif arraylen(results.len) is 0>
      <cfset arrayappend(results.len, 0)>
      <cfset arrayappend(results.pos, 0)>
   </cfif>

   <!--- and return results --->
   <cfreturn results>
</cffunction>

</cfcomponent>